﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace WmsApp.UI
{
    public partial class QPayApplyBill : QInStoreBill, IQueryControl
    {
        public QPayApplyBill()
        {
            InitializeComponent();
            if (GlobalClass.RunTimeMode)
            {
                DataBinding.Binding.BindingSystemUser(this.lookUpEditChargeID3);
                DataBinding.Binding.BindingSystemUser(this.lookUpEditManagerID3);
                DataBinding.Binding.BindingSystemUser(this.lookUpEditOperatorID3);
                DataBinding.Binding.BindingBillState(this.lookUpEditPayApplyBillState);

                var list = new List<ICheckQuerierItem>();
                list.Add(CheckQuerierItemFactory.Create("未确认", this.checkQuerier1));
                list.Add(CheckQuerierItemFactory.Create("未付款", this.checkQuerier1));
                list.Add(CheckQuerierItemFactory.Create("部分付款", this.checkQuerier1));
                list.Add(CheckQuerierItemFactory.Create("已付款", this.checkQuerier1));

                checkQuerier1.BindingCheckQuerierItem(list);
            }

        }

        #region IQueryControl Members

        public new string GetCondition()
        {
            string condition = base.GetCondition();
            if (String.IsNullOrEmpty(condition))
            {
                condition = " and 1=1 ";
            }
            else
            {
                condition = String.Format(" and InBillID in ( select BillID from dbo.InStoreBill where 1=1  {0} )", condition);
            }

            if (!String.IsNullOrEmpty(this.comboBoxEditPayApplyDept3.Text.Trim()))
            {
                condition += (String.Format(" and PayApplyDept  like '%{0}%'", this.comboBoxEditPayApplyDept3.Text.Trim()));
            }

            if (this.lookUpEditChargeID3.EditValue != null && !String.IsNullOrEmpty(lookUpEditChargeID3.EditValue.ToString()))
            {
                condition += (String.Format(" and ChargeID ='{0}'", lookUpEditChargeID3.EditValue));
            }

            if (this.lookUpEditManagerID3.EditValue != null && !String.IsNullOrEmpty(lookUpEditManagerID3.EditValue.ToString()))
            {
                condition += (String.Format(" and ManagerID ='{0}'", lookUpEditManagerID3.EditValue));
            }

            if (this.lookUpEditOperatorID3.EditValue != null && !String.IsNullOrEmpty(lookUpEditOperatorID3.EditValue.ToString()))
            {
                condition += (String.Format(" and OperatorID ='{0}'", lookUpEditOperatorID3.EditValue));
            }

            if (this.lookUpEditPayApplyBillState.EditValue != null && !String.IsNullOrEmpty(lookUpEditPayApplyBillState.EditValue.ToString()))
            {
                condition += (String.Format(" and PayApplyState ='{0}'", lookUpEditPayApplyBillState.EditValue));
            }

            if (!String.IsNullOrEmpty(this.textEditPayApplyBillID.Text.Trim()))
            {
                condition += (String.Format(" and PayApplyBillID like '%{0}%'", textEditPayApplyBillID.Text.Trim()));
            }

            string query = this.checkQuerier1.GetQueryCondition();
            if (!String.IsNullOrEmpty(query))
            {
                condition += (" and PayState in " + query);
            }
            return condition;
        }

        #endregion
    }
}
